Generated code - QuerySpec, Typed views in Dynamic Queries

Although the QueryFactory doesn't offer properties to create an EntityQuery<T> based on a TypedView, it's possible to use TypedView fields in a DynamicQuery and fetch the data using projections into custom constructs. This makes it possible to utilize the underlying mapped database view in a read-only fashion without the necessity of a mapped Entity.

Below are two examples which show the fetch of a part of the Invoices TypedView mapped on the Northwind view Invoices. The TypedView could have been fetched using normal built-in fetch logic (Adapter, SelfServicing), however if you want to fetch the data into a different construct (e.g. DTO classes or anonymous types) or fetch parts of the view into the TypedView instance, QuerySpec is a good alternative and often easier to use.

// Fetch the data in an anonymous type using a DynamicQuery<T>
var qf = new QueryFactory();
var q = qf.Create()
	.Select(() => new
	{
		CustomerId = InvoicesFields.CustomerId.ToValue<string>(),
		CustomerName = InvoicesFields.CustomerName.ToValue<string>(),
		OrderId = InvoicesFields.OrderId.ToValue<int>()
	})
	.Where(InvoicesFields.Country.StartsWith("U"));
// SelfServicing
var results = new TypedListDAO().FetchQuery(q);
// Adapter
// var results = adapter.FetchQuery(q);


// Fetch the data in an instance of the InvoicesTypedView.
var qf = new QueryFactory();
var q = qf.Create()
	.Select(InvoicesFields.CustomerId, InvoicesFields.CustomerName, InvoicesFields.OrderId)
	.Where(InvoicesFields.Country.StartsWith("U"));

var tv = new InvoicesTypedView();
// SelfServicing
new TypedListDAO().FetchAsDataTable(q, tv);
// Adapter
// adapter.FetchAsDataTable(q, tv);


LLBLGen Pro Runtime Framework v3.5 documentation. ©2012 Solutions Design bv